package com.share.service;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * 
 * 
 * <p>Title: BaseRedisServiceTest </p>
 * <p>Description: codis-API测试
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:redis.xml" })
public class BaseRedisServiceTestCodis {
	
	private static final Logger LOGGER = Logger.getLogger(BaseRedisServiceTestCodis.class);
	
	@Autowired
	BaseRedisService baseRedisService;
	
	@Test
	public void test_expireAt(){
		Timestamp t = Timestamp.valueOf("2017-11-13 17:50:00");
		Date date = new Date(t.getTime());
		System.out.println(date);
		
		String key = "test:expireAt:1";
		String value = "value";
		baseRedisService.add(key, value);		
		baseRedisService.expireAt(key, date);
		System.out.println(baseRedisService.ttl(key));
		
		baseRedisService.expireAt(key, t);
		System.out.println(baseRedisService.ttl(key));
	}
	
	
	@Test 
	public void test_add(){
		String key = "k1";
		String value = "value-201702101700";
		baseRedisService.delete(key);
		
		baseRedisService.add(key, value);		
		String result = baseRedisService.query(key, String.class);
		assertEquals(value, result);
		
		baseRedisService.delete(key);
	}
	
	@Test 
	public void test_lua(){
		List<String> keys = new ArrayList<>();
		List<String> values = new ArrayList<>();
		String k1 = "k1";
		String k2 = "k2";
		String v1 = "aa";
		String v2 = "bb";
		keys.add(new String("k1"));
		keys.add(new String("k2"));
		values.add(new String("aa"));
		values.add(new String("bb"));
		baseRedisService.excuteLua(keys, values);
		
	}
	
	
}

